﻿using System.Collections.Generic;
using System;
using System.Data;
using System.Data.Entity;
using System.Linq;
using System.Web;
namespace QuocHoi_TV_Frontend.Models
{
    public class SiteMenuManager
    {
        private QuocHoi_TVEntities db = new QuocHoi_TVEntities();
        public List<ISiteLink> GetSitemMenuItems()
        {
            try
            {
                var Categories = db.Categories
               .Where(p => p.LanguageID == 1 && p.BitVertical == false && p.IsActive == true)
                     .OrderBy(p => p.OrderPos).Take(15);
                var items = new List<ISiteLink>();
                // Top Level
                items.Add(new SiteMenuItem
                {
                    Id = 1,
                    ParentId = 0,
                    Text = "Trang chủ",
                    Url = "/Default",
                    OpenInNewWindow = false,
                    SortOrder = 0
                });
                foreach (var itemcat in Categories)
                {
                    items.Add(new SiteMenuItem
                    {
                        Id = int.Parse(itemcat.CateID.ToString()),
                        ParentId = int.Parse(itemcat.ParentId.ToString()),
                        Text = itemcat.CateName,
                        Url = "/" + Util.RemoveSign4VietnameseString(itemcat.CateName) + "/" + itemcat.CateID.ToString(),
                        OpenInNewWindow = false,
                        SortOrder = int.Parse(itemcat.OrderPos.ToString())
                    });
                }
                items.Add(new SiteMenuItem
                {
                    Id = 200,
                    ParentId = 0,
                    Text = "Sơ đồ",
                    Url = "/Default/MapSite",
                    OpenInNewWindow = false,
                    SortOrder = 200
                });
                items.Add(new SiteMenuItem
                {
                    Id = 201,
                    ParentId = 0,
                    Text = "Góp ý",
                    Url = "/Default/Contact",
                    OpenInNewWindow = false,
                    SortOrder = 201
                });
                items.Add(new SiteMenuItem
                {
                    Id = 202,
                    ParentId = 0,
                    Text = "Liên hệ",
                    Url = "/Default/About",
                    OpenInNewWindow = false,
                    SortOrder = 202
                });
                return items;
            }
            catch (Exception)
            {
                return null;
            }
           
        }
        public List<ISiteLink> GetSitemMenuItemsVertical()
        {
            try
            {
                var Categories = db.Categories
               .Where(p => p.LanguageID == 1 && p.BitVertical == true && p.IsActive == true)
                     .OrderBy(p => p.OrderPos).Take(12);
                var items = new List<ISiteLink>();
                // Top Level
                foreach (var itemcat in Categories)
                {
                    items.Add(new SiteMenuItem
                    {
                        Id = int.Parse(itemcat.CateID.ToString()),
                        ParentId = int.Parse(itemcat.ParentId.ToString()),
                        Text = itemcat.CateName,
                        Url = "/" + Util.RemoveSign4VietnameseString(itemcat.CateName) + "/" + itemcat.CateID.ToString(),
                        OpenInNewWindow = false,
                        SortOrder = int.Parse(itemcat.OrderPos.ToString())
                    });
                }
                return items;
            }
            catch (Exception)
            {
                
                return null;
            }
           
        }
    }
}